package com.Map_Practice;

public class Danlu {
	public static void login() {
		System.out.println("登录：");
		while (true) {
			System.out.println("请输入用户名：");
			String username = Input.sc.nextLine();
			System.out.println("请输入密码：");
			String password = Input.sc.nextLine();

			Result result = loginService(username, password);
			System.out.println(result.getMsg());
			if (result.isStatus()) {
				break;
			}
		}
	}

	static private Result loginService(String username, String password) {
		Result result = new Result();
		Admins admin = null;

		try {
			admin = Admins.valueOf(username);
		} catch (Exception e) {
		}
		if (admin == null) {
			return result.fail("用户不存在！");
		}
		if (!admin.getPassword().equals(password)) {
			return result.fail("密码错误！");
		} 
			Context.setCur(admin);
			return result.success("登录成功！");
		
	}

	public static Result logout() {
		Context.setCur(null);
		Result result = new Result();
		return result.success("恭喜您，登出成功");
	}
}
